var tree = layui.tree
    ,layer = layui.layer
    ,table = layui.table
    ,$ = layui.jquery,form=layui.form,laydate = layui.laydate;
lay('.starttime').each(function(){
    laydate.render({
        elem: this
    });
});
var data = [{
    title: '一级1'
    ,id: 1
    ,field: 'name1'
    ,checked: true
    ,spread: true
    ,children: [{
        title: '二级1-1'
        ,id: 3
        ,field: 'name11'
        ,children: [{
            title: '三级1-1-3'
            ,id: 23
            ,field: ''
            ,children: [{
                title: '四级1-1-3-1'
                ,id: 24
                ,field: ''
                ,children: [{
                    title: '五级1-1-3-1-1'
                    ,id: 30
                    ,field: ''
                },{
                    title: '五级1-1-3-1-2'
                    ,id: 31
                    ,field: ''
                }]
            }]
        },{
            title: '三级1-1-2'
            ,id: 8
            ,field: ''
            ,children: [{
                title: '四级1-1-2-1'
                ,id: 32
                ,field: ''
            }]
        }]
    },{
        title: '二级1-2'
        ,id: 4
        ,spread: true
        ,children: [{
            title: '三级1-2-1'
            ,id: 9
            ,field: ''
        },{
            title: '三级1-2-2'
            ,id: 10
            ,field: ''
        }]
    },{
        title: '二级1-3'
        ,id: 20
        ,field: ''
        ,children: [{
            title: '三级1-3-1'
            ,id: 21
            ,field: ''
        },{
            title: '三级1-3-2'
            ,id: 22
            ,field: ''
        }]
    }]
},{
    title: '一级2'
    ,id: 2
    ,field: ''
    ,spread: true
    ,children: [{
        title: '二级2-1'
        ,id: 5
        ,field: ''
        ,spread: true
        ,children: [{
            title: '三级2-1-1'
            ,id: 11
            ,field: ''
        },{
            title: '三级2-1-2'
            ,id: 12
            ,field: ''
        }]
    },{
        title: '二级2-2'
        ,id: 6
        ,field: ''
        ,children: [{
            title: '三级2-2-1'
            ,id: 13
            ,field: ''
        },{
            title: '三级2-2-2'
            ,id: 14
            ,field: ''
            ,disabled: true
        }]
    }]
},{
    title: '一级3'
    ,id: 16
    ,field: ''
    ,children: [{
        title: '二级3-1'
        ,id: 17
        ,field: ''
        ,fixed: true
        ,children: [{
            title: '三级3-1-1'
            ,id: 18
            ,field: ''
        },{
            title: '三级3-1-2'
            ,id: 19
            ,field: ''
        }]
    },{
        title: '二级3-2'
        ,id: 27
        ,field: ''
        ,children: [{
            title: '三级3-2-1'
            ,id: 28
            ,field: ''
        },{
            title: '三级3-2-2'
            ,id: 29
            ,field: ''
        }]
    }]
}];
var data1 = [{'id':'1','operator':'text1','customernumber':'text2','proportion':'text3','signedcontract':'text4','amount':'text5','foldtheyuan':'text6'},{'id':'2','operator':'text1','customernumber':'text2','proportion':'text3','signedcontract':'text4','amount':'text5','foldtheyuan':'text6'}
,{'id':'3','operator':'text1','customernumber':'text2','proportion':'text3','signedcontract':'text4','amount':'text5','foldtheyuan':'text6'},{'id':'4','operator':'text1','customernumber':'text2','proportion':'text3','signedcontract':'text4','amount':'text5','foldtheyuan':'text6'}];
 tree.render({
    elem: '#statisticslist' //默认是点击节点可进行收缩
    ,data: data
    ,click: function(obj){
         //判断是否有选中的列，有则取消换现点击列
         var selecteds = $(".selecteds");
         if(typeof (selecteds[0])!="undefined"){
             selecteds.removeClass("selecteds");
         }
         obj.elem[0].classList.add("selecteds");
         table.reload('statisticstableid', {
             data:data1 ,
             page: {
                 curr: 1 //重新从第 1 页开始
             }
             ,where: obj.data.id
         }, 'data');
    }
});
table.render({
    elem: '#statistics'
    ,data:data1
    ,toolbar: '#toolbarDemo'
    ,cols: [[
        {type:"numbers",width:50}
        ,{field:'operator', title:'操作员'}
        ,{field:'customernumber', title:'客户数量',sort:true}
        ,{field:'proportion', title:'比例（%）',sort:true}
        ,{field:'signedcontract', title:'已签约客户数',sort:true}
        ,{field:'amount',width:90, title:'金额',sort:true}
        ,{field:'foldtheyuan', title:'折人民币金额',sort:true}
    ]]
    ,id: 'statisticstableid'
    ,height: $(document).height() - $('#statistics').offset().top - 50
    ,page: true
});
form.on('submit(submitform)', function(data){
    layer.msg(JSON.stringify(data.field));
    table.reload('statisticstableid', {
        data:data1 ,
        page: {
            curr: 1 //重新从第 1 页开始
        }
        ,where: data.field
    }, 'data');
    return false;
});
